package com.qys.livesMall.app.user.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.app.user.model.dto.rw.AuditRw;
import com.qys.livesMall.app.user.model.dto.sys.SysUserRechargePageDTO;
import com.qys.livesMall.app.user.model.entity.H2AppUserRechargeWithdrawals;
import com.qys.livesMall.app.user.model.vo.sys.AppUserRWRankingVO;
import com.qys.livesMall.app.user.model.vo.sys.UserRWChannelStatisticsVO;
import com.qys.livesMall.app.user.service.IH2AppUserRechargeWithdrawalsService;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.finance.enums.AccountBusinessTypeEnum;
import com.qys.livesMall.framework.view.BaseQuery;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 后台管理用户充值
 * Created by IntelliJ IDEA.
 * User: dp
 * Date: 2023/04/27
 * Time: 11:03
 * DESCRIPTION: 后台管理用户充值
 */
@Slf4j
@RestController
@Tag(name = "后台管理-用户充值(提现)审核")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SysAppUserRechargeWithdrawalsController {

    private final IH2AppUserRechargeWithdrawalsService userRechargeService;

    @PostMapping("/sys/app/user/recharge/page")
    @Operation(summary = "分页查询用户充值审核信息")
    public R<Page<H2AppUserRechargeWithdrawals>> page(@RequestBody SysUserRechargePageDTO rechargePageDTO) {
        rechargePageDTO.setType(AccountBusinessTypeEnum.RECHARGE.getType());
        return R.ok(userRechargeService.page(rechargePageDTO));
    }

    /**
     * 审核
     *
     * @param id
     * @param remark
     * @param amount
     * @return
     */
    @PutMapping({"/sys/app/user/recharge/audit/{id}", "/sys/app/user/withdrawals/audit/{id}"})
    @Operation(
            summary = "审核用户充值/提现信息",
            parameters = {
                    @Parameter(name = "id", description = "id"),
                    @Parameter(name = "remark", description = "审核不通过备注"),
                    @Parameter(name = "type", description = "审核状态"),
                    @Parameter(name = "amount", description = "实际金额", required = true)
            }
    )
    public R<Void> audit(@PathVariable String id,
                         @RequestParam(required = false, name = "remark") String remark,
                         @RequestParam(required = true, name = "type") Integer type,
                         @RequestParam(value = "amount", required = false) BigDecimal amount) {
        log.info("接收到参数:remark{},type{},id{},amount{}",remark,type,id,amount);
        userRechargeService.audit(id, remark, amount, type);
        return R.ok();
    }

    /**
     * 审核通过
     * @param auditRw
     * @return
     */
    @PostMapping("/auditPass")
    public R auditPass(@RequestBody AuditRw auditRw){
        return userRechargeService.auditPass(auditRw);
    }

    /**
     * 审核不通过
     * @param auditRw
     * @return
     */
    @PostMapping("/auditNoPass")
    public R auditNoPass(@RequestBody AuditRw auditRw){
        auditRw.setType((byte) 2);
        return userRechargeService.auditNoPass(auditRw);
    }


    /**
     * @param rechargePageDTO
     * @return
     */
    @PostMapping("/sys/app/user/withdrawals/page")
    @Operation(summary = "分页查询用户提现审核信息")
    public R<Page<H2AppUserRechargeWithdrawals>> withdrawalsPage(@RequestBody SysUserRechargePageDTO rechargePageDTO) {
        rechargePageDTO.setType(AccountBusinessTypeEnum.WITHDRAWAL.getType());
        return R.ok(userRechargeService.page(rechargePageDTO));
    }

    @DeleteMapping({"/recharge/{id}", "/withdrawals/{id}"})
    @Operation(summary = "根据id删除申请信息")
    public R<Void> removeById(@PathVariable Long id) {
        userRechargeService.removeById(id);
        return R.ok();
    }

    @PostMapping("/sys/app/user/rwranking/page")
    @Operation(summary = "分页查询用户充值提现排行榜")
    public R<Page<AppUserRWRankingVO>> page(@RequestBody BaseQuery baseQuery) {
        return R.ok(userRechargeService.rwrankingPage(baseQuery));
    }

    @PostMapping("/sys/app/user/channel/statistics")
    @Operation(summary = "查询用户充值提现通道提现")
    public R<List<UserRWChannelStatisticsVO>> getRWChannelStatistics(){
        return R.ok(userRechargeService.getRWChannelStatistics());
    }
}
